﻿
@using WebApp.Models 

@model MenuItem

@{
    ViewBag.Title = "菜单管理";
}




<div class="container-fluid">
    <!-- Page Heading -->
    <div class="row">
        <div class="col-lg-12">
            <h1 class="page-header">
                菜单管理
                <small></small>
            </h1>
            <ol class="breadcrumb">
                <li>
                    <i class="fa fa-home"></i>  @Html.ActionLink("Home", "Index", "Home")
                </li>
                <li>
                    <i class="fa fa-folder-open"></i>  @Html.ActionLink("MenuItems", "Index", "MenuItems")
                </li>
                <li class="active">
                    <i class="fa fa-file"></i> 编辑
                </li>
            </ol>
        </div>
    </div>
    <!-- /.row -->
    <div class="row">
        <div class="col-lg-12">

            @using (Html.BeginForm())
            {
                @Html.AntiForgeryToken()
                <div class="form-horizontal">
                    <h4>编辑</h4>
                    <hr />
                    @Html.ValidationSummary(true, "", new { @class = "text-danger" })
                    @Html.Partial("EditForm")
                    <div class="form-group">
                        <p></p>
                        <div class="text-center">
                            <input type="submit" class="btn btn-primary" value=" 保存 " />
                            <input type="button" class="btn btn-default" data-toggle="modal" data-target="#myModal" value=" 删除 " />
                        </div>
                    </div>
                </div>
            }
        </div>
    </div>
</div>

<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel">Warning !!</h4>
            </div>
            <div class="modal-body">
                Are you sure you want to delete this item ?
            </div>
            <div class="modal-footer">
                @using (Html.BeginForm("Delete", "MenuItems", new { id = Model.Id }))
                {
                    @Html.AntiForgeryToken()
                    <button type="button" class="btn btn-default" data-dismiss="modal"> 取消 </button>
                    <button type="submit" class="btn btn-warning"> 保存 </button>
                }
            </div>
        </div>
    </div>
</div>

@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
    <script type="text/javascript">

        var menuitemid = 0;
        var ObjectState = "Modified";

        var $submenustable = {};
        $(document).ready(function () {
            menuitemid = $('#Id', 'form').val();
            $('form').submit(function () {
                if (!$('form').valid())
                    return false;
                var token = $('[name=__RequestVerificationToken]').val();
                var serializedForm = $(this).serialize();
                var actionurl = $(this).attr('action');

                var submenus = $submenustable.bootstrapTable('getData');

                var newitem = {


                    Code: $('#Code', 'form').val(),
                    Description: $('#Description', 'form').val(),
                    //primaryKey
                    Id: menuitemid,
                    IsEnabled: $('#IsEnabled', 'form').val(),
                    //detailTables
                    SubMenus: submenus,
                    Title: $('#Title', 'form').val(),
                    Url: $('#Url', 'form').val(),
                    ParentId: $('#ParentId :selected', 'form').val(),
                    ObjectState: ObjectState
                };
                $.ajax({
                    url: actionurl,
                    type: "POST",
                    dataType: "json",
                    contentType: "application/json; charset=utf-8",
                    data: JSON.stringify(newitem),
                    success: function (result) {
                        if (result.success) {
                            self.location = "/MenuItems/Index";
                        } else {
                            alert(result.err);
                        }

                    },
                    error: function (result) {
                        console.log(result.statusText + result.responseText);
                        alert(result.statusText + result.responseText);
                    }
                });
                return false;


            });
        });

    </script>

}